﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Web.UI.WebControls;
using TuyennvLibrary.Reflection;
using TuyennvLibrary.ServerApi.Util;

namespace ServerApi.administrator
{
    public partial class DescriptionClassManager : System.Web.UI.Page
    {
        public string title = "Mô tả class ";
        public int stt = 1;
        List<FileInfo> filesdll = new List<FileInfo>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadFileDlls();
                loadDesscriptionClass();
            }
        }
        public void loadFileDlls()
        {
            filesdll = ApiUtilities.getFiles(Server.MapPath("/FileDLL/"), new string[] { ".dll" });
            foreach (FileInfo f in filesdll)
            {
                ddlFileDll.Items.Add(new ListItem { Text = f.Name, Value = f.Name });
            }
            ddlFileDll.Items.Insert(0, new ListItem { Text = "ServerApi.dll", Value = "" });
        }

        protected void ddlFileDll_SelectedIndexChanged(object sender, EventArgs e)
        {
            loadDesscriptionClass();
        }
        private void loadDesscriptionClass()
        {
            List<DescriptionClass> list = new List<DescriptionClass>();
            int type = 1;
            if (!string.IsNullOrEmpty(Request["typeclass"]))
            {
                type = int.Parse(Request["typeclass"]);
            }

            list = loadListDescription(ddlFileDll.Text, type);

            GrvListDescription.DataSource = list;
            GrvListDescription.DataBind();
        }
        public List<DescriptionClass> loadListDescription(string dllName, int type)
        {
            List<DescriptionClass> list = new List<DescriptionClass>();

            string pathdll = "";
            if (!string.IsNullOrEmpty(dllName))
            {
                pathdll = Server.MapPath("/FileDLL/" + dllName);
            }
            list = ApiUtilities.getListDescriptionClass(pathdll, type);
            return list;
        }
    }
}